using System;
using UnityEngine;

public class MidLoading : MonoBehaviour
{
	public static int loadlevel;

	private AsyncOperation async;

	private int progress;

	private int toprogress;

	public UILabel percentlabel;

	public UISprite slidersp;

	public Transform thumbtra;

	public UISprite bgsp;

	private float endx;

	private float ratio;

	public UILabel tipslabel;

	private int tipsindex;

	private void Awake()
	{
		GC.Collect();
		Resources.UnloadUnusedAssets();
	}

	private void Start()
	{
		async = Application.LoadLevelAsync(loadlevel);
		progress = 0;
		GlobalInf.loading_over = false;
		tipsindex = UnityEngine.Random.Range(0, GlobalInf.tips.Length);
		tipslabel.text = "提示:" + GlobalInf.tips[tipsindex];
		GameLoad.tipsindex = tipsindex;
		MenuLoad.tipsindex = tipsindex;
	}

	private void Update()
	{
		if (async != null && !async.isDone)
		{
			toprogress = (int)(async.progress * 100f);
		}
		if (progress < toprogress)
		{
			progress++;
		}
		percentlabel.text = progress + "%";
		slidersp.fillAmount = (float)progress / 100f;
		ratio = -0.5f + (float)progress / 100f + 0.05f;
		if (ratio > 0.5f)
		{
			ratio = 0.5f;
		}
		endx = (float)bgsp.width * ratio;
		thumbtra.localPosition = new Vector3(endx, 0f, 0f);
		if (loadlevel == 2)
		{
			GameLoad.curprogress = progress;
		}
		else if (loadlevel == 0)
		{
			MenuLoad.curprogress = progress;
		}
	}
}
